// core
import { createApp, Directive } from 'vue'
import App from '@/App.vue'
import store from '@/store'
import router from '@/router'
import '@/permission'

// css

import 'element-plus/dist/index.css'
import 'element-plus/theme-chalk/dark/css-vars.css'
import 'virtual:uno.css' // unocss
import 'normalize.css'
import '@/styles/index.scss'

import 'virtual:svg-icons-register' // 引入注册脚本

import { registerGlobalComponents } from '@/utils/register-components'

const app = createApp(App)

// 加载自定义指令
import * as directives from '@/directives'
Object.keys(directives).forEach(key => {
  app.directive(key, (directives as { [key: string]: Directive })[key])
})

// 将信息克隆并挂到 window 上，方便查看
window.__APP_INFO__ = JSON.parse(JSON.stringify(__APP_INFO__))
// 默认将项目名称和版本号打印到控制台上
console.info(`${__APP_INFO__.title} | ${__APP_INFO__.version} | ${__APP_INFO__.mode}`)

app.use(store).use(router)
// 注册组件
registerGlobalComponents(app)

router
  .isReady()
  .then(() => {
    app.mount('#app')
  })
  .catch(error => {
    console.error(error)
  })
